/*
Write a function named firstNonRepeatingCharacter that takes a string input, and returns the first character that is not repeated anywhere in the string.

For example, if given the input 'stress', the function should return 't', since the letter t only occurs once in the string, and occurs first in the string.

As an added challenge, upper- and lowercase letters are considered the same character, but the function should return the correct case for the initial letter. For example, the input 'sTreSS' should return 'T'.

If a string contains all repeating characters, it should return the empty string ("").
*/

function firstNonRepeatingLetter(s) {
    let arr = [];
    for (let i = 0; i < s.length; i++) {
        let index = -1;
        arr.forEach((word, _index) => {
            if (word.toLowerCase() === s[i].toLowerCase()) index = _index;
        });
        index === -1 ? arr.push(s[i]) : arr.splice(index, 1);
    }
    return arr[0] || '';
}

function firstNonRepeatingLetter(s) {
    var t = s.toLowerCase();
    for (var x = 0; x < t.length; x++)
        if (t.indexOf(t[x]) === t.lastIndexOf(t[x]))
            return s[x];
    return "";
}

function firstNonRepeatingLetter(s) {
    for (var i in s) {
        if (s.match(new RegExp(s[i], "gi")).length === 1) {
            return s[i];
        }
    }
    return '';
}